package com.abaaba.project2.controller.wxcontroller;

import com.abaaba.project2.bean.bo.wx.WxFeedbackBo;
import com.abaaba.project2.bean.vo.BaseRespVo;
import com.abaaba.project2.service.WxFeedbackService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("/wx/feedback")
public class WxFeedbackController {
    @Autowired
    WxFeedbackService wxFeedbackService;
    @Autowired
    WxAuthController wxAuthController;

    @RequestMapping("/submit")
    public BaseRespVo saveFeedback(@RequestBody WxFeedbackBo wxFeedbackBo) {
        Session session = wxAuthController.subject.getSession();

        String filePath = (String) session.getAttribute("filePath");

        if (filePath != null && !"".equals(filePath)) {
            wxFeedbackBo.setHasPicture(true);
            wxFeedbackBo.setPicUrls(new String[] {filePath});
        }

        wxFeedbackService.saveFeedback(wxFeedbackBo);

        // 提交后，移除 session 中的数据
        session.removeAttribute("filePath");
        return BaseRespVo.ok();
    }
}
